<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>

<form:form id="sparepartForm" commandName="model" cssClass="validate"
	action="sparepart/sparepart/save">
		<form:hidden path="id" />
		<input type="hidden" id="sourceId" name="sourceId"
			value="${sourceId }" /> <input type="hidden" id="ty" name="ty"
			value="${ty }" />
		<form:hidden path="useStatus" />
     <div id="confCiTab" class="box tabbedBox">
		<div class="header">
			<ul>
				<li class="current"><a href="#tab1">基本信息</a>
				</li>
				<li class="current"><a href="#tab2">出入库履历(<label
							id="ciRelatedCiSparepartCount" style="color:red">0</label>)</a>
				</li>
			</ul>
		</div>

		<div style="padding:0" class="content tabbed">

			<div id="tab1">

				<div class="header">
					<h2>
						&nbsp;&nbsp;备件信息<span><font color="red">（* 为必填项）</font> </span>
					</h2>
				</div>

				<table class=" form-table">
					<tr>
						<td class="td1">编号：</td>
						<td class="td2"><form:input path="code" />
						</td>
						<td class="td1">分类：</td>
						<td class="td2"><form:hidden path="sptSparepartCategoryId" />
							<isperp:treeSelector id="selectParentProjectCategory"
								url="sparepart/category/getTree"
								valueControlId="sptSparepartCategoryId"
								displayValue="${categoryName}" displayValueCssClass="required"></isperp:treeSelector>
						</td>
					</tr>

					<tr>
						<td class="td1">名称：</td>
						<td class="td2"><form:input path="name" cssClass="required" />
						</td>
						<td class="td1">设备号/PN号：</td>
						<td class="td2"><form:input path="devideNumber"
								cssClass="required" /></td>
					</tr>

					<tr>
						<td class="td1">序列号：</td>
						<td class="td2"><form:input path="sn" cssClass="required"
								cssStyle="" /></td>

						<td class="td1">入库日期：</td>
						<td class="td2"><form:input path="stockInDate" cssClass=""
								cssStyle="" type="date" /></td>
					</tr>
					<tr>
						<td class="td1">责任人：</td>
						<td class="td2"><form:hidden path="useStaffId" /> <isperp:departmentUser
								displayValue="${model.useStaffName }"
								valueControlId="useStaffId" idFieldName="name" id="useStaffName"
								ifIncludeNoRoleUser="false" name="useStaffName"
								multiselect="false" displayValueCssClass="required"></isperp:departmentUser>
						</td>

						<td class="td1">使用人：</td>
						<td class="td2"><form:hidden path="supportStaffId" /> <isperp:departmentUser
								displayValue="${model.supportStaffName }"
								valueControlId="supportStaffId" idFieldName="name"
								id="supportStaffName" ifIncludeNoRoleUser="false"
								name="supportStaffName" multiselect="false"
								displayValueCssClass=""></isperp:departmentUser>
						</td>
					</tr>

					<tr>
						<td class="td1">厂商：</td>
						<td class="td2"><form:input path="manufacturer" cssClass=""
								cssStyle="" /></td>

						<td class="td1">状态：</td>
						<td class="td2"><isperp:dictSelector
								typeCode="SPAREPART_STATUS" name="status" id="status"
								hasEmptyValue="true" dictCssClass="required"
								selectedValue="${model.status }"></isperp:dictSelector>
						</td>
					</tr>

					<tr>

						<td class="td1">供应商：</td>
						<td class="td2"><form:hidden
								path="manufacturerProviderId" /> <isperp:listSelector
								id="manufacturerProviderName" url="provider/provider/list"
								displayValue="${model.manufacturerProviderName }"
								name="manufacturerProviderName"
								displayValueCssStyle="width:150px;"
								valueControlId="manufacturerProviderId">
								<isperp:column name="id" title="id" hidden="true"></isperp:column>
								<isperp:column name="code" title="编号" width="80">
								</isperp:column>
								<isperp:column name="name" title="名称" width="150">
								</isperp:column>
								<isperp:column name="linkman" title="联系人" width="80">
								</isperp:column>
								<isperp:column name="linktel" title="联系电话" width="80">
								</isperp:column>
								<isperp:column name="serviceTel" title="客服电话" width="80">
								</isperp:column>
							</isperp:listSelector></td>
							
						<td class="td1">价格：</td>
						<td class="td2"><form:input path="price" cssClass="number"
								cssStyle="" /></td>
					</tr>
					<tr>
						<td class="td1">项目：</td>
						<td class="td2" colspan="3"><form:hidden path="projectName" />
							<form:select path="projectId" items="${projects }"
								itemLabel="name" itemValue="id" cssClass="search"></form:select>
						</td>
					</tr>
					<tr>

						<td class="td1">位置：</td>
						<td class="td2" colspan="3"><form:input path="location"
								cssClass="" cssStyle="width:80%" /></td>

					</tr>


					<tr>
						<td class="td1">备注：</td>
						<td class="td2" colspan="3"><form:textarea path="remark" />
						</td>
					</tr>

				</table>
			</div>
			<div id="tab2">
			   <isperp:grid url="sparepart/sparepartRelation/findCiSparepart"
						urlExtScript="function(){return '?ciId=${model.id }'}"
						gridId="ciRelationSparepartGrid" showPager="true" height="auto"
						showSearchbar="false" sortname="create_date" sortorder="desc"
						showToolbar="false" cusActions="gridActions(rowObject)"
						loadComplete="$('#ciRelatedCiSparepartCount').text( ciRelationSparepartGrid.jqGrid.getGridParam('records'));">
						<jsp:attribute name="toolbar">
						</jsp:attribute>
						<jsp:body>
							<isperp:column name="id" title="id" hidden="true"></isperp:column>
							<isperp:column name="code" title="编号">
							</isperp:column>
							<isperp:column name="memo" title="描述">
							</isperp:column>
							<isperp:column name="creator_name" title="填表人">
							</isperp:column>
							<isperp:column name="create_date" title="填报日期">
							</isperp:column>
							<isperp:column name="ktype" title="类型">
							</isperp:column>
							<isperp:column name="type_key" title="类型1" hidden="true">
							</isperp:column>
							<isperp:column name="status" title="流程状态">
							</isperp:column>
						</jsp:body>
					</isperp:grid>
			</div>

		</div>


	</div>
</form:form>

<isperp:buttonList>
	<button class="submit"
		onclick="isperp.submitForm({success : function() { isperp.reloadGrid('sparepartGrid');isperp.closeDialog(); }}); return false;">
		<span class="icon icon-save"></span>提交
	</button>
</isperp:buttonList>
<script type="text/javascript">
	function clearCusUser2() {
		$("#supportStaffId").val("");
		$("#cusUserIdSelector2").val("");
	}
	
	function gridActions(rowObject) {
        var url="";
        if(rowObject.type_key=="sparepartIn")
        {
            url="sparepart/sparepartIn/view?id="+rowObject.id;
        }else if(rowObject.type_key=="sparepartOut")
        {
           url="sparepart/sparepartOut/view?id="+rowObject.id;
        }else if(rowObject.type_key=="sparepartDiscard")
        {
           url="sparepart/sparepartDiscard/view?id="+rowObject.id;
        }else if(rowObject.type_key=="sparepartBack")
        {
           url="sparepart/sparepartBack/view?id="+rowObject.id;
        }
       
		return isperp.createGridAction({
			title : '查看',
			iconCls : 'icon-view',
			onclick : "isperp.openDialog({title:'查看',contentUrl:'"+url+"'})"
		});
	}

	function clearCusUser1() {
		$("#useStaffId").val("");
		$("#cusUserIdSelector1").val("");
	}
	function setCheckedCategoryTreeNodes() {

		var nodes = categoryTree.zTree.getCheckedNodes(true);

		var nStr = "";
		$(nodes).each(function(index, node) {
			nStr += node.id + ",";
		});

		$("#categoryIdValue").val(nStr);
		return true;
	}

	function minStockUseRule_onchange() {

		var minStockUseRuleCheck = $("input[name='minStockUseRule']:checked").val();

		if (minStockUseRuleCheck) {

			$("#isMinStockUseRule").show();
			$("#minStock").hide();
			var treeObj = $.fn.zTree.getZTreeObj("categoryTree");
			treeObj.setting.async.url = "sparepart/sparepart/getConfCategorys?sparepartId=${model.id}";

			categoryTree.reload();

		} else {
			$("#isMinStockUseRule").hide();
			$("#minStock").show();
		}

	}

	$(function() {
		if ('${model.code}' == '') {
			$.ajax({
				url : 'configuration/ci/getSeqByTableName?tableName=spt_sparepart',
				success : function(data) {
					if (data) {
						$("#code").val(data);
					}
				}
			});
		}

		var projectId = '${model.projectId}';
		if (!projectId) {
			$("#projectId").val("");
			$("#projectId").trigger("chosen:updated");
		}

	});

	//minStockUseRule_onchange();
</script>
